package field

import "gitee.com/yanwc/net/utils"

type (
	AlarmType    uint8 // 告警类型
	AlarmTypeRaw [1]byte
)

func (a AlarmType) Raw() (out AlarmTypeRaw) {
	copy(out[:], utils.NumberToBytesWithBigEndian(a))
	return
}

func (a AlarmTypeRaw) Type() AlarmType {
	return utils.BytesToNumber[AlarmType](a[:])
}

func (a AlarmTypeRaw) Slice() []byte {
	return a[:]
}

func (nt AlarmType) Description() string {
	return EventNotifies[nt]
}

const (
	OutDistrictWarn        AlarmType = 0x01 // 出服务围栏告警
	InDistrictWarn         AlarmType = 0x02 // 入服务围栏告警
	MoveWarn               AlarmType = 0x03 // 非法移动告警
	LowBatteryWarn         AlarmType = 0x04 // 低电压通知，低于50%告警一次
	CriticalLowBatteryWarn AlarmType = 0x05 // 严重低电压告警，低于30%告警一次
	AutoLockNotify         AlarmType = 0x13 // 自动落锁通知
	SideDownNotify         AlarmType = 0x27 // 倾倒事件通知
	RecoverSideDownNotify  AlarmType = 0x28 // 倾倒恢复通知
	OutAlertFenceNotify    AlarmType = 0x32 // 出告警围栏通知
	InAlertFenceNotify     AlarmType = 0x33 // 入告警围栏通知
	DragBikeWarn           AlarmType = 0x52 // 拖车告警
)

var EventNotifies = map[AlarmType]string{
	OutDistrictWarn:        "出服务围栏告警",
	InDistrictWarn:         "入服务围栏告警",
	MoveWarn:               "非法移动告警",
	LowBatteryWarn:         "低电压通知,低于50%告警一次",
	CriticalLowBatteryWarn: "严重低电压告警,低于30%告警一次",
	AutoLockNotify:         "自动落锁通知",
	SideDownNotify:         "倾倒事件通知",
	RecoverSideDownNotify:  "倾倒恢复通知",
	OutAlertFenceNotify:    "出告警围栏通知",
	InAlertFenceNotify:     "入告警围栏通知",
	DragBikeWarn:           "拖车告警",
}
